package com.enjoyor.health.HGPT.core.service.impl;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.enjoyor.health.HGPT.core.entity.News;
import com.enjoyor.health.HGPT.core.mapper.NewsMapper;
import com.enjoyor.health.HGPT.core.service.INewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author enjoyor
 * @since 2023-10-18
 */
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements INewsService {

    @Override
    public List<News> getNewsList() {
        return baseMapper.getNewsList();
    }

    @Override
    public int updateNewsLike(String newsId) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("news_id", newsId);
        return baseMapper.updateLike(map);
    }

    @Override
    public Page<News> getNewsPage(String type, String status, String title, int page, int size) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("type", type);
        map.put("status", status);
        map.put("title", title);
        Page<News> p = new Page<>(page, size);
        p.addOrder(OrderItem.desc("up"), OrderItem.desc("edit_time"));
        return baseMapper.getNewsPage(p, map);
    }
}
